package cn.hr.controller;

import cn.hr.service.DataAnalysisService;
import cn.hr.service.DictionaryService;
import cn.hr.service.OrganizationService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by MO on 2019/1/14.
 */
@Controller
@RequestMapping("/dataAnalysis")
public class DataAnalysisController {
    @Resource
    private OrganizationService organizationService;
    @Resource
    private DictionaryService dictionaryService;
    @Resource
    private DataAnalysisService dataAnalysisService;

    @RequestMapping("/subsidiary")
    public String subsidiary(Model model) {
        Map map = new HashMap();
        map.put("parentId", 0);
        map.put("isStart", 1);
        try {
            model.addAttribute("organizationList", organizationService.findSubdivisionByParentId(map));
            model.addAttribute("archivesStatusList", dictionaryService.selectAllByTypeName("STATUS_TYPE"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "dataAnalysis/subsidiary";
    }

    @RequestMapping("/subsidiaryShow")
    public String subsidiaryShow(@RequestParam(required = false) Map map, @RequestParam("pageNo") String pageNo, Model model) {
        try {
            model.addAttribute("pageInfo", dataAnalysisService.findArchivesByCondition(map, Integer.parseInt(pageNo)));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "dataAnalysis/subsidiaryShow";
    }

    @RequestMapping("/consolidatedStaffDataReport/show")
    public String consolidatedStaffDataReport(Model model) {
        try {
            Map map = dataAnalysisService.findConsolidatedStaffDataReport();
            model.addAttribute("list", map.get("list"));
            model.addAttribute("educations", map.get("educations"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "dataAnalysis/staffDataReport";
    }

    @RequestMapping("/consolidatedStaffDataReport_o/show/{year}")
    public String consolidatedStaffDataReportO(@PathVariable("year") String year, Model model) {
        try {
            Map map = dataAnalysisService.findConsolidatedStaffDataReportO(year);
            model.addAttribute("year", year);
            model.addAttribute("list", map.get("list"));
            model.addAttribute("educations", map.get("educations"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "dataAnalysis/staffDataReportO";
    }

}

